#include "TouchArea.h"
#include "s3e.h"
#include "Sprite.h"
#include "Iw2D.h"

TouchArea::TouchArea()
{ }

// calculated the "correct" size for a touch area
// based on the size of the sprite
// touch area needs to be larger than the actual
// button for most effective use
void TouchArea::CalcSizeForSprite( const Sprite &sprite )
{
	m_size.x = sprite.GetWidth() * 1.5f;
	m_size.y = sprite.GetHeight() * 1.5f;
}

// pos is the op left corner
void TouchArea::SetPos( CIwFVec2 pos )
{
	m_pos = pos;
}

void TouchArea::SetSize( CIwFVec2 size )
{
	m_size = size;
}

bool TouchArea::IsWithin( uint touch ) const
{
	// get the position from the touch interface
	CIwFVec2 touch_pos( (float)s3ePointerGetTouchX(touch), (float)s3ePointerGetTouchY(touch) );

	return (touch_pos.x > m_pos.x && touch_pos.x < m_pos.x + m_size.x &&
	        touch_pos.y > m_pos.y && touch_pos.y < m_pos.y + m_size.y);
}

#ifdef _DEBUG
void TouchArea::DrawDebug( )
{
	CIwSVec2 p0s( (int) m_pos.x, (int) m_pos.y );
	CIwSVec2 size_s( (int) m_size.x, (int) m_size.y );
	
	Iw2DSetColour( 0xFF000000 );
	Iw2DFillRect( p0s, size_s );
	Iw2DSetColour(0xFFFFFFFF);
}
#endif